Message: Handle Edger App Messages
This message
module provides multiple interfaces for applications to handle messages.
Developers can determine whether these interfaces work in the EdgerOS mobile App environment through the following code:
edger.env().then(data => {
if (data.env === 'edgerapp') {
// We work in EdgerOS mobile App environment.
}
}).catch(error => {
console.error(error);
});
Developers can call this API to update the app's message status, and the app's notification red dot will automatically hide when all messages are read or cleared.
Functions
edger.app.message.read(ids)
ids
{String[]} An array of unique message IDs generated when calling notify.push.- Returns: {Promise} Promise object.
Update the status of selected messages to read
and EdgerOS will then hide them in the Message Center.
Example
const ids = [ 'xxxxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxxx', 'xxxxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx1' ];
edger.app.message.read(ids).then((data) => {
if (data.status === 'success') {
console.log('read message success!');
}
}).catch(error => {
console.error(error);
});
async / await
const ids = [ 'xxxxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxxx', 'xxxxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx1' ];
async function readMessage() {
try {
const data = await edger.app.message.read(ids);
if (data.status === 'success') {
console.log('read message success!');
}
} catch(error) {
console.error(error);
}
}
edger.app.message.readByType(type)
type
{String} Letter type generated when calling notify.push.- Returns: {Promise} Promise object.
Update the status of all messages to read
and EdgerOS will hide them in the Message Center.
Example
edger.app.message.readByType('home').then((data) => {
if (data.status === 'success') {
console.log('message has read success!');
}
}).catch(error => {
console.error(error);
});
async / await
async function readByType() {
try {
const data = await edger.app.message.readByType('home');
if (data.status === 'success') {
console.log('message has read success!');
}
} catch (error) {
console.error(error);
}
}
edger.app.message.clearAll()
Clear all messages sent to phone by the app.
Example
edger.app.message.clearAll().then((data) => {
if (data.status === 'success') {
console.log('ok!');
}
}).catch(error => {
console.error(error);
});
async / await
async function clearAll() {
try {
const data = await edger.app.message.clearAll();
if (data.status === 'success') {
console.log('ok!');
}
} catch(error) {
console.error(error);
}
}